package com.sky.mapper;

import com.sky.annotation.AutoFill;
import com.sky.dto.DishDTO;
import com.sky.dto.DishPageQueryDTO;
import com.sky.entity.Category;
import com.sky.entity.Dish;
import com.sky.enumeration.OperationType;
import com.sky.vo.DishVO;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface DishMapper {

    /**
     * @description: 根据分类id查询该分类是否有菜品
     * @author: tanbobin
     * @date: 2024/6/3 14:31
     * @param:
     * @param id
     * @return:
     * @return java.util.List<java.lang.String>
     **/
    @Select("select name from dish where category_id = #{id}")
    public List<String> queryById(Long id);

    /**
     * @description: 保存菜品基本信息
     * @author: tanbobin
     * @date: 2024/5/30 16:52
     * @param:
     * @param dish
     * @return:
     **/
    @AutoFill(OperationType.INSERT)
    @Options(useGeneratedKeys = true, keyProperty = "id")
    @Insert("insert into dish (name, category_id, price, image, description, status, create_time, update_time, create_user, update_user)" +
            "    values (#{name}, #{categoryId}, #{price}, #{image}, #{description}, #{status}, #{createTime}, #{updateTime}, #{createUser},#{updateUser})")
    void insert(Dish dish);

    /**
     * @description: 分页查询
     * @author: tanbobin
     * @date: 2024/5/31 10:02
     * @param:
     * @param pageQueryDTO
     * @return:
     * @return java.util.List<com.sky.entity.Dish>
     **/
    List<DishVO> list(DishPageQueryDTO pageQueryDTO);

    /**
     * @description: 根据 id 统计起售菜品的数量
     * @author: tanbobin
     * @date: 2024/5/31 11:34
     * @param:
     * @param ids
     * @return:
     * @return java.lang.Long
     **/
    Long countEnableDishByIds(List<Long> ids);

    /**
     * @description: 批量删除菜品数据
     * @author: tanbobin
     * @date: 2024/5/31 15:16
     * @param:
     * @param ids
     * @return:
     **/
    void deleteByIds(List<Long> ids);

    /**
     * @description: 根据 id 查询菜品基本信息
     * @author: tanbobin
     * @date: 2024/5/31 16:03
     * @param:
     * @param id
     * @return:
     * @return com.sky.entity.Dish
     **/
    @Select("select * from dish where id = #{id}")
    Dish getDishInfo(Long id);

    /**
     * @description: 动态修改菜品基本信息
     * @author: tanbobin
     * @date: 2024/5/31 16:35
     * @param:
     * @param dish
     * @return:
     **/
    @AutoFill(OperationType.INSERT)
    void updateDish(Dish dish);

    /**
     * @description: 查询菜品，及菜品口味数据
     * @author: tanbobin
     * @date: 2024/6/5 10:12
     * @param:
     * @param categoryId
     * @return:
     * @return java.util.List<com.sky.vo.DishVO>
     **/
    List<DishVO> listDishWithFlavors(Dish dish);



    /**
     * @description: 根据分类 id 查询菜品信息
     * @author: tanbobin
     * @date: 2024/5/31 17:52
     * @param:
     * @param id
     * @return:
     * @return java.lang.Long
     **/
//    @Select("select count(*) from dish where category_id = #{id}")
//    Long queryDishById(Long id);
}
